package com.enjoy.mjbaseframe.base;

import android.widget.Toast;

import com.enjoy.mjbaseframe.R;
import com.enjoy.mjbaseframe.okgo.OkGoLoader;
import com.lzy.okgo.OkGo;

import java.util.ArrayList;
import java.util.List;

import me.yokeyword.fragmentation.SupportFragment;

/**
 * fragment基础类,两次点击返回键退出关闭activity
 * Created by YoKeyword on 16/6/5.
 */
public abstract class BaseMainFragment extends BaseFragment {
    // 再点一次退出程序时间设置
    private static final long WAIT_TIME = 2000L;
    private long TOUCH_TIME = 0;

    /**
     * 处理回退事件
     *
     * @return
     */
    @Override
    public boolean onBackPressedSupport() {
        if (System.currentTimeMillis() - TOUCH_TIME < WAIT_TIME) {
            _mActivity.finish();
        } else {
            TOUCH_TIME = System.currentTimeMillis();
            Toast.makeText(_mActivity, R.string.press_again_exit, Toast.LENGTH_SHORT).show();
        }
        return true;
    }

    /**
     * 因为启动的BrotherFragment是MainFragment的兄弟Fragment,所以需要MainFragment.start()
     * 也可以像使用getParentFragment()的方式,拿到父Fragment来操作 或者使用 EventBusActivityScope
     * @param targetFragment
     */
    public void startBrotherFragment(SupportFragment targetFragment) {
        ((BaseMainFragment)getParentFragment()).start(targetFragment);
    }

    @Override
    public void onDestroy() {

        super.onDestroy();
    }
}
